import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from "axios"

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI)
// 引入组件
// import 自定义组件对象名 from "./components/组件.vue"

// 将引入组件转为全局组件-(可在项目中任一组件的html中用全局组件标签)
// Vue.component("标签名",自定义组件对象名)

//配置axios
// axios.defaults.baseURL="https://saihanyun.cklock.cn/adminchoice/" //线上
axios.defaults.baseURL="https://ceshi3.cklock.cn/adminchoice/" //测试

console.log(process)
// axios.defaults.baseURL=process.env.NODE_ENV
// switch(process.env.NODE_ENV){
//   case "production":
//       axios.defaults.baseURL="http://39.103.141.171:9103"
//       break;
//   case "test":
//       axios.defaults.baseURL="http://39.103.141.171:9103" 
//       break;
//   default:
//       axios.defaults.baseURL="http://localhost:8080"
// }
// axios.defaults.baseURL="http://192.168.5.104:8081"

axios.interceptors.request.use(config=>{
  config.headers["authorization-admin"] = window.sessionStorage.getItem('token');
  console.log('token',window.sessionStorage.getItem('token'))
  config.headers["Content-Type"] = "application/json;charset=UTF-8";
  // if(config.method=="post")
  return config;
})

Vue.prototype.axios=axios
Vue.config.productionTip = false

//路由守卫 路由开始前进行操作
router.beforeEach((to,from,next)=>{
  if(to.path==="/"){
    next();
  }
  const token = window.sessionStorage.getItem('token');
  if(token){
    next();
  }else{
    next("/");
  }
})

//路由拦截
// router.beforeEach((to,from,next)=>{
//   if(to.meta.requireAuth){
//     console.log(to.meta.requireAuth)
//     console.log(store.state.islogin)
//     if(store.state.islogin){
//       next()
//     }else{
//       next({path:'/'})
//     }
//   }else{next()}
// })


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
